package com.lz.football.module.playerUp
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.core.TitleWindow;
	import lz.controls.managers.AnimationManager;
	import lz.controls.managers.TipsManager;

	/**
	 *球员升级动画 
	 * @author Administrator
	 * 
	 */	
	public class PlayerUpView extends TitleWindow implements IPlayerUpView
	{
		private var playerVo:PlayerVo
		private var _shape:Shape;
		/**
		 * 
		 */
		private var _obj:Object;
		
		public function PlayerUpView()
		{
			super();
		}
		
		public function set data(value:*):void
		{
			_obj= value;
			playerVo = AppData.getInstance().playerCenterDataManager.getplayerVoById(_obj.playerid);
			_symbolSkin.gotoAndPlay(1);
			
			_symbolSkin.lvMc.lv.text = "恭喜您！升至"+playerVo.level+"级";
			_symbolSkin.playerCard.mc.gotoAndStop(playerVo.color);
			var frameIndex :int = 1;
			var maxValue   :int = 100;
			//进度条
			frameIndex = playerVo.attack / maxValue * 11;
			_symbolSkin.playerCard.mc.attackProMc.gotoAndStop(frameIndex);
			frameIndex = playerVo.defence / maxValue * 11;
			_symbolSkin.playerCard.mc.defenceProMc.gotoAndStop(frameIndex);
			frameIndex = playerVo.steal / maxValue * 11;
			_symbolSkin.playerCard.mc.stealProMc.gotoAndStop(frameIndex);
			frameIndex = playerVo.power / maxValue * 11;
			_symbolSkin.playerCard.mc.powerProMc.gotoAndStop(frameIndex);
			frameIndex = playerVo.speed / maxValue * 11;
			_symbolSkin.playerCard.mc.speedProMc.gotoAndStop(frameIndex);
			frameIndex = playerVo.control / maxValue * 11;
			_symbolSkin.playerCard.mc.controlProMc.gotoAndStop(frameIndex);
			
			
			_symbolSkin.playerCard.mc.control.value.text = playerVo.control + "";
			_symbolSkin.playerCard.mc.speed.value.text = playerVo.speed + "";
			_symbolSkin.playerCard.mc.power.value.text = playerVo.power + "";
			_symbolSkin.playerCard.mc.steal.value.text = playerVo.steal + "";
			_symbolSkin.playerCard.mc.defence.value.text = playerVo.defence + "";
			_symbolSkin.playerCard.mc.attack.value.text = playerVo.attack + "";
			if(_obj.attachAdd > 0)
			{
				_symbolSkin.playerCard.mc.attack.value.htmlText = _obj.attach// + "<font color = '#00FF00'>"+"+"+ _obj.attachAdd + "</font>";
				_symbolSkin.playerCard.mc.attack.addvalue.htmlText = "+"+_obj.attachAdd  +"";
				
			}else
			{
				_symbolSkin.playerCard.mc.attack.value.htmlText = playerVo.attack + "";
				_symbolSkin.playerCard.mc.attack.addvalue.htmlText  = "";
			}
			if(_obj.speedAdd > 0)
			{
				_symbolSkin.playerCard.mc.speed.value.htmlText = _obj.speed //+ "<font color = '#00FF00'>"+"+"+ _obj.speedAdd+ "</font>";
				_symbolSkin.playerCard.mc.speed.addvalue.htmlText = "+"+_obj.speedAdd  +"";
			}else
			{
				_symbolSkin.playerCard.mc.speed.value.htmlText = playerVo.speed + "";
				_symbolSkin.playerCard.mc.speed.addvalue.htmlText = "";
			}
			if(_obj.controlAdd > 0)
			{
				_symbolSkin.playerCard.mc.control.value.htmlText = _obj.control + ""//+"<font color = '#00FF00'>"+ "+"+ _obj.controlAdd+ "</font>";
				_symbolSkin.playerCard.mc.control.addvalue.htmlText = "+"+_obj.controlAdd  +"";
			}else
			{
				_symbolSkin.playerCard.mc.control.value.htmlText = playerVo.control + "";
				_symbolSkin.playerCard.mc.control.addvalue.htmlText = "";
			}
			if(_obj.powerAdd > 0)
			{
				_symbolSkin.playerCard.mc.power.value.htmlText = _obj.power +""//+"<font color = '#00FF00'>"+ "+"+ _obj.powerAdd+ "</font>";
				_symbolSkin.playerCard.mc.power.addvalue.htmlText ="+"+ _obj.powerAdd +"";
			}else
			{
				_symbolSkin.playerCard.mc.power.value.htmlText = playerVo.power + "";
				_symbolSkin.playerCard.mc.power.addvalue.htmlText = "";
			}
			if(_obj.stealAdd > 0)
			{
				_symbolSkin.playerCard.mc.steal.value.htmlText = _obj.steal +""// "<font color = '#00FF00'>"+"+"+ _obj.stealAdd+ "</font>";
				_symbolSkin.playerCard.mc.steal.addvalue.htmlText = "+"+_obj.stealAdd +"";
			}else
			{
				_symbolSkin.playerCard.mc.steal.value.htmlText = playerVo.steal + "";
				_symbolSkin.playerCard.mc.steal.addvalue.htmlText ="";
			}
			if(_obj.defenceAdd > 0)
			{
				_symbolSkin.playerCard.mc.defence.value.htmlText = _obj.defence + ""//"<font color = '#00FF00'>"+"+"+ _obj.defenceAdd+ "</font>";
				_symbolSkin.playerCard.mc.defence.addvalue.htmlText ="+"+_obj.defenceAdd + "";
			}else
			{
				_symbolSkin.playerCard.mc.defence.value.htmlText = playerVo.defence + "";
				_symbolSkin.playerCard.mc.defence.addvalue.htmlText = "";
			}
			
			_symbolSkin.playerCard.mc.ability.text = playerVo.ability + "";
			_symbolSkin.playerCard.mc.txtName.text = playerVo.starVo.pname;
			_symbolSkin.playerCard.mc.txtLv.text = playerVo.level + "";
			_symbolSkin.playerCard.mc.txtPlace.text = playerVo.place_String ;
			_symbolSkin.addFrameScript(_symbolSkin.totalFrames -1,onPlayerFinish);
			addEvtListener();
			onResizerHandler();
		}
		private function onframeHandler(evnet:Event):void
		{
			var text:TextField ;
//			if(text)text.text = playerVo.attack + "";
//			text = _symbolSkin.playerCard.mc.control.value
//			if(text)text.text = playerVo.control + "";
//			text = _symbolSkin.playerCard.mc.speed.value
//			if(text)text.text = playerVo.speed + "";
//			text = _symbolSkin.playerCard.mc.power.value
//			if(text)text.text = playerVo.power + "";
//			text = _symbolSkin.playerCard.mc.steal.value
//			if(text)text.text = playerVo.steal + "";
//			text = _symbolSkin.playerCard.mc.defence.value
//			if(text)text.text = playerVo.defence + "";
			
			
			text = _symbolSkin.playerCard.mc.attack.value;
			if(_obj.attachAdd > 0)
			{
				if(text)text.text  = _obj.attach + "+"+ _obj.attachAdd;
			}else
			{
				if(text)text.text = playerVo.attack + "";
			}
			//
			text = _symbolSkin.playerCard.mc.speed.value
			if(_obj.speedAdd > 0)
			{
				if(text)text.text = _obj.speed + "+"+ _obj.speedAdd;
			}else
			{
				if(text)text.text = playerVo.speed + "";
			}
			//
			text = _symbolSkin.playerCard.mc.control.value
			if(text)text.text = playerVo.control + "";
			if(_obj.controlAdd > 0)
			{
				if(text)text.text= _obj.control + "+"+ _obj.controlAdd;
			}else
			{
				if(text)text.text = playerVo.control + "";
			}
			//
			text = _symbolSkin.playerCard.mc.power.value
			if(_obj.powerAdd > 0)
			{
				if(text)text.text  = _obj.power + "+"+ _obj.powerAdd;
			}else
			{
				if(text)text.text  = playerVo.power + "";
			}
			text = _symbolSkin.playerCard.mc.steal.value
			if(_obj.stealAdd > 0)
			{
				if(text)text.text  = _obj.steal + "+"+ _obj.stealAdd;
			}else
			{
				if(text)text.text  = playerVo.steal + "";
			}
			text = _symbolSkin.playerCard.mc.defence.value
			if(_obj.defenceAdd > 0)
			{
				if(text)text.text  = _obj.defence + "+"+ _obj.defenceAdd;
			}else
			{
				if(text)text.text  = playerVo.defence + "";
			}
			
			
			//				onPlayerComp();
		
			
		}
		public function addEvtListener():void
		{
			GlobalDef.GameStage.addEventListener(Event.RESIZE,onResizerHandler);
		}
		
		public function onResizerHandler(event:Event = null):void
		{
			_symbolSkin.x = (GlobalDef.StageWidth /*- _symbolSkin.width*/>> 1) - 110;
			_symbolSkin.y = (GlobalDef.StageHeight/* - _symbolSkin.height*/>> 1) -170;
			_shape.width = GlobalDef.StageWidth;
			_shape.height = GlobalDef.StageHeight;
		}		
		private function onPlayerFinish():void
		{
			_symbolSkin.removeEventListener(Event.ENTER_FRAME,onframeHandler);
			if(_symbolSkin.btn != null)
				_symbolSkin.btn.addEventListener(MouseEvent.CLICK,onClickHandler);
			_symbolSkin.stop();
		}
		private function onClickHandler(event:MouseEvent):void
		{
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
			GlobalDef.GameStage.removeEventListener(Event.RESIZE,onResizerHandler);
			if(_symbolSkin.btn != null)
				_symbolSkin.btn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_symbolSkin.removeEventListener(Event.ENTER_FRAME,onframeHandler);
			AnimationManager.remove();
		}
		public function get data():*
		{
			return null;
		}
		
		public function initUI(view:Object=null):void
		{
			_shape = new Shape();
			_shape.graphics.clear();
			_shape.graphics.beginFill(0x000000,0.7);
			_shape.graphics.drawRect(0,0,GlobalDef.GameWidth,GlobalDef.GameHeight);
			_shape.graphics.endFill();
			this.addChild(_shape);
			_symbolSkin = Reflection.createInstance("com.lz.modul.playerUPLv");
			this.addChild(_symbolSkin);
			_symbolSkin.gotoAndStop(1);
			_symbolSkin.x = 200;
			_symbolSkin.y = 200;
			TipsManager.hide();
		}
		
		
		public function removeEvtListener():void
		{
		}
		
		public function destroyView():void
		{
		}
		
		public function showType($obj:Object):void
		{
		}
	}
}